package com.qp.basics.estivate;

import java.util.HashMap;
import java.util.Map;

public abstract class BaseDataTypeConvertor implements DataTypeConvertor {
	protected final static Map<String, String> dataTypeToJavaMapping = new HashMap();
	protected final static Map<String, String> dataTypeToStdMapping = new HashMap();
	protected final static Map<String, String> stdToDataTypeMapping = new HashMap();
	{
		dataTypeToJavaMapping.put("string", "java.lang.String");
		dataTypeToJavaMapping.put("decimal", "java.lang.Double");
		dataTypeToJavaMapping.put("int", "java.lang.Integer");
		dataTypeToJavaMapping.put("long", "java.lang.Long");
		dataTypeToJavaMapping.put("date", "java.util.Date");
		dataTypeToJavaMapping.put("datetime", "java.util.Date");
		dataTypeToJavaMapping.put("text", "java.lang.String");

		dataTypeToStdMapping.put("varchar", "string");
		dataTypeToStdMapping.put("varchar2", "string");
		dataTypeToStdMapping.put("clob", "text");
		dataTypeToStdMapping.put("text", "text");

		stdToDataTypeMapping.put("string", "varchar2");
		stdToDataTypeMapping.put("decimal", "number");
		stdToDataTypeMapping.put("int", "number");
		stdToDataTypeMapping.put("long", "number");
		stdToDataTypeMapping.put("date", "date");
		stdToDataTypeMapping.put("datetime", "date");
		stdToDataTypeMapping.put("text", "clob");
	}

	public String getJavaType(String dataType) {
		return dataTypeToJavaMapping.get(dataType.toLowerCase());
	}

	public String getStdDataType(String dataType) {
		return dataTypeToStdMapping.get(dataType.toLowerCase());
	}

	public String getDataType(String stdDataType) {
		return (String) stdToDataTypeMapping.get(stdDataType.toLowerCase());
	}

	public String getDataJavaStringValue(String stdDataType, String value) {
		String result = "";

		if (stdDataType.equals("string") || stdDataType.equals("date")
				|| stdDataType.equals("datetime")
				|| stdDataType.equals("varchar")) {
			result = "'" + value + "'";
		} else {
			if (value.length() == 0) {
				result = "null";
			} else {
				result = value;
			}
		}

		return result;
	}
}
